﻿#region
/*******************************************************************************
** File Name:		    NewsRepository.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using Phoenix.Entity;
using Phoenix.Respository;
using IBatisNet.DataMapper;
using Phoenix.Data.IBatis;
using System.Collections;

namespace Phoenix.IBatisRepository
{
    public class NewsRepository : BaseIBatisDao,INews
    {
    
		#region  Auto Generation

        public NewsRepository()
            : base("/Config/IBatis/86TCMap.Config")
        {

        }
        		
        public void AddNews(ENews entity)
        {
			string stmtId = "NewsMap.InsertNews";
            string sql=GetRuntimeSql(stmtId,entity);
			base.SqlMapper.Insert(stmtId, entity);
			
        }
        
		public  ENews GetByNewsID (System.Int32 newsID)
        {
			string stmtId = "NewsMap.SelectByNewsID";
			return base.SqlMapper.QueryForObject<ENews>(stmtId, newsID);
        }
        
        public  void DeleteByNewsID (System.Int32 newsID)
        {
			string stmtId = "NewsMap.DeleteByNewsID";
			base.SqlMapper.Update(stmtId, newsID);
        }
        
        public  void UpdateByNewsID (ENews entity)
        {
			string stmtId = "NewsMap.UpdateByNewsID";
			base.SqlMapper.Update(stmtId, entity);
        }


		#endregion

        public IList<ENews> GetPagedList(int pageSize, int pageIndex, int categoryID, out int totalRecord)
        {
            Hashtable ht = new Hashtable();
			ht.Add("CatalogID", categoryID);

			totalRecord = base.SqlMapper.QueryForObject<int>("NewsMap.SelectRecord", ht);

            if (pageIndex > totalRecord)
                pageIndex = 1;

            int startPage = pageSize * pageIndex - pageSize;

            int endPage = pageSize * pageIndex;

			ht.Add("Offset", startPage);
            ht.Add("Rows", endPage);

            //offset,rows
			string stmtId = "NewsMap.SelectPagedList";

			string sql = GetRuntimeSql(stmtId, ht);
            return base.SqlMapper.QueryForList<ENews>(stmtId, ht);


        }


    }
}

